using System;
using System.Collections.Generic;
using System.Text;
using CodePlex.Resourceful.Json;

namespace CodePlex.Resourceful.Metaweb
{
    public class MqlBuilder : JsonBuilder
    {

        public IDisposable StartQueryUnique(string qname)
        {
            IDisposable rt1 = this.StartObject();

            this.WritePropertyName(qname);

            IDisposable rt2 = this.StartObject();

            this.WritePropertyName("query");

            IDisposable rt3 = this.StartObject();

            return new QuickDisposable(delegate
            {
                rt3.Dispose();
                rt2.Dispose();
                rt1.Dispose();
            });

        }

        public IDisposable StartQueryMultiple(string qname, string cursor)
        {
            IDisposable rt1 = this.StartObject();

            this.WritePropertyName(qname);

            IDisposable rt2 = this.StartObject();

            if (string.IsNullOrEmpty(cursor))
            {
                this.WriteProperty("cursor", true);
            }
            else
            {
                this.WriteProperty("cursor", cursor);
            }
            
            this.WritePropertyName("query");

            IDisposable rt3 = this.StartArray();
            IDisposable rt4 = this.StartObject();

            return new QuickDisposable(delegate
            {
                rt4.Dispose();
                rt3.Dispose();
                rt2.Dispose();
                rt1.Dispose();

            });
        }
    }

}
